package com.imooc.miaosha.dao;

import com.imooc.miaosha.pojo.domain.MiaoshaOrder;
import com.imooc.miaosha.pojo.domain.OrderInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface OrderDao {
    @Select("select * from order_info where user_id=#{userId} and goods_id=#{goodsId}")
    OrderInfo findByUserIdAndGoodsId(@Param("userId")long userId,@Param("goodsId")long goodsId);

    @Insert("insert into order_info" +
            "(user_id,goods_id,delivery_addr_id," +
            "goods_name,goods_count,goods_price," +
            "order_channel,status,create_date)" +
            "values(#{userId},#{goodsId},#{deliveryAddrId}," +
            "#{goodsName},#{goodsCount},#{goodsPrice},#{orderChannel}," +
            "#{status},#{createDate})")
    @SelectKey(keyColumn = "id", keyProperty = "id", resultType = long.class,
            before = false, statement = "select last_insert_id()")
    long insert(OrderInfo orderInfo);
    //解释一下@SelectKey,
    //keyColnum:表中的列；ketPreperty该表的列对应的domain对象的字段
    //before:
    //statement:应该是sql语句

    @Insert("insert into miaosha_order(user_id,order_id,goods_id)" +
            "values(#{userId},#{orderId},#{goodsId})")
    void insertMiaoshaOrder(MiaoshaOrder miaoshaOrder);
}
